package com.design.facaed;

import com.design.pay.AliPay;
import com.design.pay.WeChatPay;

/**
 * 支付外观类
 */
public class PaymentFacaed {
    private WeChatPay weChatPay;
    private AliPay aliPay;

    private String wechat_appId="wechat_appId";
    private String wechat_mchId="wechat_mchId";
    private String aliPay_appId="aliPay_appId";
    private String aliPay_privateKey="aliPay_privateKey";

    public PaymentFacaed() {
        weChatPay = new WeChatPay();
        weChatPay.initialize(wechat_appId, wechat_mchId);
        aliPay = new AliPay();
        aliPay.initialize(aliPay_appId, aliPay_privateKey);
    }

    public String pay(String change,String orderId) {
        if("wechat".equals(change)){
            String signOrder = weChatPay.signOrder(orderId);
            return weChatPay.sendPaymentRequest(signOrder);
        }else if("alipay".equals(change)){
            String signOrder = aliPay.signOrder(orderId);
            return aliPay.sendPaymentRequest(signOrder);
        }
        throw new RuntimeException("不支持的支付渠道");
    }

    public boolean verifyCallback(String change,String callbackData){
        if("wechat".equals(change)){
           return weChatPay.verifyCallback(callbackData);
        }else if("alipay".equals(change)){
            return aliPay.verifyCallback(callbackData);
        }
        throw new RuntimeException("不支持的支付渠道");
    }
}
